package com.daoeping.dao;

import java.util.List;
import org.json.JSONArray;
import com.daoeping.domain.Bzn_jobdescription;
import com.daoeping.domain.JsonData;
import com.daoeping.domain.Page;
import com.daoeping.domain.TableData;
import com.daoeping.util.ConverntJsonData;

public class JobDao extends AllDaoSupport{
	
	public JsonData pageBzn_jobdescriptions(Page page, TableData tableData, Bzn_jobdescription bzn_jobdescription) {
		try {
			String hql = "select bzn.title ,comp.name ,  job.name  , work.name, sal.salaryValue , edu.educationalLevel , bzn.id ,city.name from Bzn_jobdescription bzn, Bsc_city city  ,Cop_companyinfo comp , Bsc_jobtype job,Bsc_salary sal , Bsc_educational edu , Bsc_worktype work  where bzn.bsc_city.id = city.id  and comp.id = bzn.cop_companyinfo.id and job.id = bzn.bsc_jobtype.id  and sal.id = bzn.bsc_salary.id and edu.id = bzn.bsc_educational.id and work.id = bzn.bsc_worktype.id and bzn.bsc_jobtype.id in (select job.id from Bsc_jobtype  job where job.name like'%"
					+ bzn_jobdescription.getBsc_jobtype().getName()
					+ "%' ) and (bzn.bsc_city.id in (select city.id from Bsc_city city where city.name like '%"
					+ bzn_jobdescription.getBsc_city().getName()
					+ "%' ) or bzn.bsc_city.bsc_region.id in (select region.id from Bsc_region region where region.name like '%"
					+ bzn_jobdescription.getBsc_city().getName() + "%' )     )"+tableData.getOrderby();
			List<Object[]> resultlist = (List<Object[]>) this.getPageList(
					page, hql);
			JSONArray json = new ConverntJsonData().getJsonData(resultlist);
			JSONArray newJson = new JSONArray();
			newJson.put(this.getNum(page, "select count(bzn) from Bzn_jobdescription bzn"));
			for (int i = 0; i < json.length(); i++) {
				newJson.put(json.get(i));
			}
			JsonData jsonData = new JsonData();
			jsonData.setJsonData(newJson.toString());
			return jsonData;
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
	public JsonData findBzn_jobdescriptionDetailForModify(Bzn_jobdescription bzn_jobdescription) {
		try {
			List<Object[]> resultlist = (List<Object[]>) this
					.selectDataByHQL("select bzn.title , bzn.cop_companyinfo.id , bzn.bsc_jobtype.id  , bzn.bsc_city.id , bzn.bsc_city.bsc_region.id , bzn.bsc_workyear.id , bzn.bsc_salary.id , bzn.bsc_educational.id , bzn.numberOfRecruits ,  bzn.bsc_specialty.id , bzn.bsc_certificate.id , bzn.bsc_language.id , bzn.bsc_skill.id , bzn.description , bzn.bsc_worktype.id,cop.description , bzn.createdDate , city.name , bzn.id from Bzn_jobdescription bzn , Cop_companyinfo cop , Bsc_city city where bzn.id =  '"
							+ bzn_jobdescription.getId()
							+ "' and bzn.cop_companyinfo.id = cop.id and bzn.bsc_city.id = city.id ");
			JSONArray json = new ConverntJsonData().getJsonData(resultlist);
			JsonData jsonData = new JsonData();
			jsonData.setJsonData(json.toString());
			return jsonData;
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
	
}
